package com.atwork.wuhua.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.atwork.wuhua.R;
import com.atwork.wuhua.bean.TypesBean;
import com.atwork.wuhua.utils.GlideUtils.GlideUtil;
import com.atwork.wuhua.utils.LogUtils;
import com.atwork.wuhua.utils.Util;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class TypesAdapter extends BaseQuickAdapter<TypesBean.DataBean, BaseViewHolder> {
    private Context context;
    private int widch;

    public TypesAdapter(Context context, int layoutResId, @Nullable List<TypesBean.DataBean> data) {
        super(layoutResId, data);
        this.context = context;
        widch = Util.getScreenWidch((Activity) context) / 4;
    }

    @Override
    protected void convert(BaseViewHolder helper, TypesBean.DataBean item) {
        helper.addOnClickListener(R.id.lly_click).setText(R.id.tv_name, item.getName());
        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) helper.getView(R.id.img_thumb).getLayoutParams();
        linearParams.width = widch;
        helper.getView(R.id.img_thumb).setLayoutParams(linearParams);

        if (item.isSelect()) {
            ((TextView) helper.getView(R.id.tv_name)).setTextColor(context.getResources().getColor(R.color.A4d98de));
        } else {
            ((TextView) helper.getView(R.id.tv_name)).setTextColor(context.getResources().getColor(R.color.A666));
        }

        GlideUtil.loadImage(context, item.getThumb(), (ImageView) helper.getView(R.id.img_thumb));
    }
}
